//
//  RecommendPointTableViewCell.m
//  MagictoLane
//
//  Created by 锋 on 2017/12/20.
//  Copyright © 2017年 HUAYU. All rights reserved.
//

#import "RecommendPointTableViewCell.h"

@implementation RecommendPointTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        // 监听通知
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(countDownNotification) name:OYCountDownNotification object:nil];
    }
    return self;
}

#pragma mark - 倒计时通知回调
- (void)countDownNotification {
    /// 判断是否需要倒计时 -- 可能有的cell不需要倒计时,根据真实需求来进行判断
    SpotsModel *model = self.model;
    if (model.count <= 0) {
        return;
    }
    /// 计算倒计时
    NSInteger timeInterval;
    if (model.countDownSource) {
        timeInterval = [kCountDownManager timeIntervalWithIdentifier:model.countDownSource];
    }else {
        timeInterval = kCountDownManager.timeInterval;
    }
    NSInteger countDown = model.count - timeInterval;
    /// 当倒计时到了进行回调
    if (countDown <= 0) {
       //计时器等于零
        model.count = 0;
        self.timeBlock(@"0");
        return;
    }
    self.clockTimeLabel.text = [NSString stringWithFormat:@"%02zd:%02zd:%02zd", countDown/3600, (countDown/60)%60, countDown%60];
}

///  重写setter方法
- (void)setModel:(SpotsModel *)model {
    _model = model;    
    // 手动刷新数据
    [self countDownNotification];
    
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
